clc;

A=imread('mandrill_lumi.bmp');
A=imresize(A, 0.25);
%A = ones(50); A(20:50,:) = 0;

dy = [1;-1];
dx = [1,-1];

AA_x = conv2(double(A),dx,'same');
AA_y = conv2(double(A),dy,'same');

%met les contours de AA_x a 0
[rows,cols] = size(AA_x);
AA_x(1,:) = 0;
AA_x(cols,:) = 0;
AA_x(:,1) = 0;
AA_x(:,rows) = 0;

%met les contours de AA_y a 0
[rows,cols] = size(AA_y);
AA_y(1,:) = 0;
AA_y(cols,:) = 0;
AA_y(:,1) = 0;
AA_y(:,rows) = 0;

norm = sqrt(AA_x.*AA_x+AA_y.*AA_y);

%on ne garde que les valeurs < 50
AA_x( find( norm<50 ) ) = 0;
AA_y( find( norm<50 ) ) = 0;

figure;clf;
imagesc(A);colormap(gray);axis image; % A image source
hold on;
scale_quiver=10;

quiver(AA_x, AA_y, scale_quiver,'b');
quiver(-AA_y, AA_x, scale_quiver,'.r');
quiver(AA_y,-AA_x,scale_quiver,'.r');